package com.approval.approvalapp.myself;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.approval.approvalapp.MyAppliaction;
import com.approval.approvalapp.R;
import com.approval.approvalapp.bean.MyInfoBean;
import com.approval.approvalapp.index.cygn.yjcn.YjcnListActivity;
import com.approval.approvalapp.login.LoginActivity;
import com.approval.approvalapp.myself.activity.WdHysSqActivity;
import com.approval.approvalapp.myself.activity.WdbjActivity;
import com.approval.approvalapp.myself.activity.WdbsActivity;
import com.approval.approvalapp.myself.activity.WdkqActivity;
import com.approval.approvalapp.myself.activity.WdqjActivity;
import com.approval.approvalapp.myself.activity.WdwzActivity;
import com.approval.approvalapp.util.AppConfig;
import com.approval.approvalapp.util.SpUtil;
import com.approval.approvalapp.util.base.BaseFragment;
import com.approval.approvalapp.util.net.NetRequsetUtil;
import com.approval.approvalapp.util.net.interfacepac.NetDownResponse;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyselfFragment extends BaseFragment {

    @Bind(R.id.name_tv)
    TextView nameTv;
    @Bind(R.id.dw_tv)
    TextView dwTv;
    @Bind(R.id.wdqj_num_tv)
    TextView wdqjNumTv;
    @Bind(R.id.wdqj_ll)
    LinearLayout wdqjLl;
    @Bind(R.id.wdwz_num_tv)
    TextView wdwzNumTv;
    @Bind(R.id.wdwz_ll)
    LinearLayout wdwzLl;
    @Bind(R.id.hysyd_num_tv)
    TextView hysydNumTv;
    @Bind(R.id.hysyd_ll)
    LinearLayout hysydLl;
    @Bind(R.id.wdbj_rl)
    RelativeLayout wdbjRl;
    @Bind(R.id.wdkq_rl)
    RelativeLayout wdkqRl;
    @Bind(R.id.wdbs_rl)
    RelativeLayout wdbsRl;
    @Bind(R.id.jyyj_rl)
    RelativeLayout jyyjRl;
    @Bind(R.id.exit_rl)
    RelativeLayout exitRl;
    @Bind(R.id.civ)
    CircleImageView civ;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_myself;
    }

    @Override
    public void initView(View view) {
        Glide.with(this.getActivity()).load(SpUtil.getString(this.getActivity(),SpUtil.USER_AVATER,""))
                .into(civ);
        nameTv.setText(SpUtil.getString(MyAppliaction.getInstance(), SpUtil.USER_RUN_NICKNAME, ""));
        dwTv.setText(SpUtil.getString(MyAppliaction.getInstance(), SpUtil.UNIT_NAME, ""));
            if (SpUtil.getString(this.getActivity(),SpUtil.Usertype,"")
                    .equals("3")){
                    wdbjRl.setVisibility(View.GONE);
            }
    }

    @Override
    public void initData() {
        NetRequsetUtil.getInstance().netRequestGet("v1/Center/index", new NetDownResponse() {
            @Override
            public void success(String str) {
                Gson gson = new Gson();
                MyInfoBean myInfoBean = gson.fromJson(str, MyInfoBean.class);
                wdqjNumTv.setText(myInfoBean.getList().getLeave());
                wdwzNumTv.setText(myInfoBean.getList().getMaterial());
                hysydNumTv.setText(myInfoBean.getList().getRoom());

            }

            @Override
            public void errowithresponse(String str) {

            }

            @Override
            public void erro() {

            }

            @Override
            public void finish() {

            }
        });
    }


    @OnClick({R.id.wdbj_rl, R.id.wdkq_rl, R.id.wdbs_rl, R.id.jyyj_rl, R.id.exit_rl,
            R.id.wdqj_ll, R.id.wdwz_ll, R.id.hysyd_ll})
    public void onViewClicked(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.wdbj_rl:
                intent.setClass(this.getActivity(), WdbjActivity.class);
                startActivity(intent);
                break;
            case R.id.wdkq_rl:
                intent.setClass(this.getActivity(), WdkqActivity.class);
                startActivity(intent);
                break;
            case R.id.wdbs_rl:
                intent.setClass(this.getActivity(), WdbsActivity.class);
                startActivity(intent);
                break;
            case R.id.jyyj_rl:
                intent.setClass(this.getActivity(), YjcnListActivity.class);
                startActivity(intent);
                break;
            case R.id.wdqj_ll:
                intent.setClass(this.getActivity(), WdqjActivity.class);
                startActivity(intent);
                break;
            case R.id.wdwz_ll:
                intent.setClass(this.getActivity(), WdwzActivity.class);
                startActivity(intent);
                break;
            case R.id.hysyd_ll:
                intent.setClass(this.getActivity(),WdHysSqActivity.class);
                startActivity(intent);
                break;
            case R.id.exit_rl:
                //退出登录 修改配置
                SpUtil.saveString(MyAppliaction.getInstance(), SpUtil.USER_RUN_ID, "-1");
                SpUtil.saveString(MyAppliaction.getInstance(), SpUtil.INDEXCACHE, "");
                this.getActivity().finish();
                intent.setClass(this.getActivity(),LoginActivity.class);
                startActivity(intent);
                break;
        }
    }
}
